package com.cyf.mq.producer;

import com.cyf.mq.constant.MqConstant;
import com.cyf.mq.pojo.HeroDTO;
import com.cyf.mq.util.JacksonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.util.UUID;

/**
 * @author chenyifan
 * @create 2025-02-19 9:15
 */
@Slf4j
public class RepeatedProducer {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer(MqConstant.MESSAGE_PRODUCER_GROUP_A);
        producer.setNamesrvAddr(MqConstant.NAME_SERVER_ADDR);
        producer.start();

        String key = UUID.randomUUID().toString();
        log.info("key:{}", key);

        Message message = new Message(MqConstant.MESSAGE_TOPIC_King, null, key, "库存扣减-1".getBytes());
        Message repeatMessage = new Message(MqConstant.MESSAGE_TOPIC_King, null, key, "库存扣减-1".getBytes());
        SendResult sendResult1 = producer.send(message);
        SendResult sendResult2 = producer.send(repeatMessage);
        log.info("发送结果：{}", sendResult1);
        log.info("发送结果：{}", sendResult2);
        producer.shutdown();
    }
}
